import java.util.ArrayList;
import java.util.List;

public class PartitionLabels {
    public List<Integer> partitionLabels(String s) {
        //将题目可以转换成跳跃字符II
        int[] array=new int[26];
        //计算模拟数组跳跃
        for (int i = 0; i < s.length(); i++) {
            char c = s.charAt(i);
            array[c-'a']=i;
        }
        List<Integer> list=new ArrayList<>();
        int curRight=0;
        int nextRight=0;
        //注意应该是s.length,不同于II
        for (int i = 0; i < s.length(); i++) {
            char c = s.charAt(i);
            nextRight=Math.max(nextRight,array[c-'a']);
            if(i==curRight){
                list.add(nextRight-curRight+1);
                curRight=nextRight;
            }
        }
        return list;
    }
}
